package com.tengju.user.domain.model.protocol;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProtocolVersion {

    ProtocolType protocolType;

    Integer protocolVersion;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ProtocolVersion that = (ProtocolVersion) o;
        return protocolType == that.protocolType &&
                Objects.equals(protocolVersion, that.protocolVersion);
    }

    public int compare(ProtocolVersion version) {
        if (this.protocolVersion > version.getProtocolVersion()) {
            return 1;
        } else if (this.protocolVersion.equals(version.getProtocolVersion())) {
            return 0;
        } else {
            return -1;
        }
    }

}
